package com.xk857.forum.mapper.provider;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;

import java.util.List;

/**
 * @author CV大魔王
 * @Description 话题动态SQL
 * @date 2021/2/22 21:57
 */
public class ForumProvider {


    /**
     * 新增话题标签中间表数据
     * @param forumId 话题id
     * @param labelIds 标签id
     * @return sql语句
     */
    public String saveForumLabel(String forumId, List<String> labelIds) {
        StringBuilder sql = new StringBuilder();
        sql.append("INSERT INTO xk857_forum_label(id, forum_id, label_id) VALUES ");
        for (int i = 0; i < labelIds.size(); i++) {
            if (i == labelIds.size() - 1) {
                sql.append(" ( ").append(IdWorker.getId()).append(", ").append(forumId).append(" , ").append(labelIds.get(i)).append(" ) ");
            }else {
                sql.append(" ( ").append(IdWorker.getId()).append(", ").append(forumId).append(" , ").append(labelIds.get(i)).append(" ), ");
            }
        }
        return sql.toString();
    }

}
